home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / l2c-19.exe / LISP2C19.TXT < prev    next >
Text File  |  1993-06-25  |  36KB  |  830 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10. (C) 1993 BASIC d.o.o Ljubljana,
  11. Jure Spiler,
  12. Jesenkova 5,
  13. 61000 Ljubljana, Slovenia
  14. tel: +386 1 314 069
  15. fax: +386 1 318 211
  16. CompuServe: [70541,1765]
  17. e-mail:
  18. Jure Spiler, director    jure.spiler@public1.noprmd.mail.si
  19. Joze Marincek    joze.marincek@uni-lj.si
  20.  
  21.  
  22.  
  23. Lisp2C
  24.                 
  25. AutoLISP to C (ADS) treanslator 
  26. user's guide
  27.  
  28.  
  29.  
  30.  
  31.  
  32. version 1.9 (22-June-1993)
  33.  
  34.  
  35. Table of Contents
  36. Table of Contents    2
  37. 1. INTRODUCTION    3
  38. 2. INSTALLATION    4
  39. 2.1.DOS - WATCOM    4
  40. 2.2.DOS - METAWARE    4
  41. 2.3.WINDOWS - WATCOM    4
  42. 2.4.WINDOWS - METAWARE    5
  43. 2.5. DOS Example (Watcom)    5
  44. 3. THE USAGE    6
  45. 3.1. COMMAND LINE INPUT    6
  46. 3.2. INTERACTIVE INPUT    7
  47. 3.3. PROJECT FILE    8
  48. 3.4. SWITCHES    8
  49. 3.5. COMPILING THE CODE (WATCOM)    9
  50. 3.6. LINKING (WATCOM)    10
  51. 3.7. BINDING (WATCOM)    10
  52. 4. SUPPORTED FUNCTIONS    11
  53. 5. DIFFERENCES AND LIMITATIONS    12
  54. 5.1. EXPRESSIONS OUTSIDE THE FUNCTIONS    12
  55. 5.2 NUMBER OF ARGUMENTS    12
  56. 5.3. PASSING SYMBOLS, SUBROUTINES ETC.    12
  57. 5.4. PASSING LISTS OF INTEGERS ETC.    12
  58. 5.5. BUILD-IN PRIMITIVES    12
  59. 5.6. GLOBAL SYMBOLS    12
  60. 5.7. A SYMBOL TABLE    13
  61. 5.8. NENTSEL, NENTSELP    13
  62. 5.9. ATOMS-FAMILY    13
  63. 5.10. COMMAND    13
  64. 5.12. SPEED    13
  65. 6. FEATURES    14
  66. 6.1. A GARBAGE COLLECTOR    14
  67. 6.2. S::L2CSTARTUP FUNCTION    14
  68. 6.3. AUTOMATIC S::L2CSTARTUP GENERATION    14
  69. 6.4. SCOPING    14
  70. 6.5. MEM FUNCTION    14
  71. 6.6. DEBUGGER    14
  72. 7. A PROGRAMMER'S VIEW    15
  73. 7.1. SymExp    15
  74. 7.2. A FUNCTION CALL MECHANISM    15
  75. 7.3. NAMING CONVENTIONS    16
  76. APPENDIX    17
  77. A. EXAMPLE: DLINE.LSP    17
  78.  
  79.  
  80. 1. INTRODUCTION
  81. Lisp2Cads translates an AutoLISP source file(s) into C source files 
  82. that can be further compiled using the Watcom  or Metaware C 
  83. compiler.
  84. Why would anyone bother to compile the existing .LISP code?
  85. First, this completely protects your algorithms. If you use ordinary 
  86. AutoLISP, you have to provide source that can be read by AutoCAD. 
  87. But then it can also be read by a human. Therefore all of your know-
  88. how is exposed to everyone interested.
  89. Second, an ADS environment is gaining more and more acceptance. 
  90. Lisp2C is a great way to preserve all your investments into Lisp 
  91. (trainig, coding) and slowly moving to the ADS.
  92. And finally, Lisp2C  also includes a debugging tool that is easy to use 
  93. yet powerful.
  94. Requirements are:
  95. *     AutoCAD R12 (Dos, Windows)
  96. *     Watcom C/386 9.0 (9.01d required for Windows), or
  97. * Metaware C/C++ 3.1 and PharLap DOS Extender/Linker
  98. You need DOS4GW.EXE to run L2C.EXE!
  99.  
  100.  
  101. Lisp2Cads consists of:
  102.  
  103. 1.    QSTART.TXT    How to quick - start LISP2C
  104.     LISP2C.DOC    This file (Word for Windows)
  105.     LISP2C.TXT    This file (ASCII)
  106. 2.    L2C.EXE        Lisp to C compiler
  107. 3.    L2C.H        Header file, included into source
  108. 4.    L2C.LIB        Libs:    (Watcom -DOS)
  109.     WINL2C.LIB    (Watcom - Windows)
  110.     MWL2C.LIB    (Metaware - DOS)
  111.     MWWINL2C.LIB    (Metaware - Windows)
  112. 5.    DEMO.LSP    Sample Lisp program 
  113. 6.    DLINE.LSP    Sample LISP from ACAD12
  114. STARTUP.LSP Direct statements from DLINE
  115. DLINE.L2C    Project file to compile DLINE.LSP
  116. Other example files may appear in distribution.
  117.  
  118.  
  119. 2. INSTALLATION
  120. 2.1.DOS - WATCOM
  121. Install your Watcom C/386 9.0 or later compiler and compile at least 
  122. one sample file (eg TOWER.C) from \ACAD\ADS, to ensure that the 
  123. compiler is set up properly.
  124. Place the files L2C.EXE (Lips2C translator) and DOS4GW.EXE 
  125. (Watcom DOS extender) into directory pointed by a system variable 
  126. PATH.  We suggest C:\DOS or C:\ACAD directory.
  127. Place L2C.LIB and L2C.H files into \ACAD\ADS directory. Point to 
  128. this directory  with L2C variable:
  129. SET L2C=C:\ACAD\ADS
  130. Change INCLUDE variable to include \ACAD\ADS directory:
  131. SET INCLUDE=C:\WATCOM\H;C:\ACAD\ADS
  132. 2.2.DOS - METAWARE
  133. Install your Metaware HighC/C++ 3.1 compiler and compile at least 
  134. one sample file (eg TOWER.C) from \ACAD\ADS, to ensure that the 
  135. compiler is set up properly.
  136. Place the files L2C.EXE (Lips2C translator) and DOS4GW.EXE 
  137. (Watcom DOS extender) into directory pointed by a system variable 
  138. PATH.  We suggest C:\DOS or C:\ACAD directory.
  139. Place MWL2C.LIB and L2C.H files into \ACAD\ADS directory. 
  140. Point to this directory  with L2C variable:
  141. SET L2C=C:\ACAD\ADS
  142. Change IPATH variable to include \ACAD\ADS directory:
  143. SET IPATH=C:\HIGHC\H;C:\ACAD\ADS
  144. Note that paths must be set before Lisp file is converted into C 
  145. source. L2C uses the values of these variables to produce .BAT and 
  146. .MW files. If those values are not set or set properly, .BAT and .MW 
  147. files may not compile the C files. This does not, however, corrupt 
  148. produced C code in any way.
  149. 2.3.WINDOWS - WATCOM
  150. Install your Watcom C/386 9.01d or later compiler and compile at 
  151. least one sample file (eg TOWER.C) from \ACADWIN\ADS, to 
  152. ensure that the compiler is set up properly.
  153. Place the files L2C.EXE (Lips2C translator) and DOS4GW.EXE 
  154. (Watcom DOS extender) into directory pointed by a system variable 
  155. PATH.  We suggest C:\DOS or C:\ACADWIN directory.
  156. Place L2CWIN.LIB and L2C.H files into \ACADWIN\ADS 
  157. directory. Point to this directory with L2C variable:
  158. SET L2C=C:\ACADWIN\ADS
  159. Change INCLUDE variable to include \ACADWIN\ADS:
  160. SET INCLUDE=C:\WATCOM\H;C:\ACADWIN\ADS
  161. Copy the file ADS.ICO from ADS\WIN directory to your working 
  162. directory.
  163. 2.4.WINDOWS - METAWARE
  164. Install your Metaware HighC/C++ 3.1 compiler and compile at least 
  165. one sample file (eg TOWER.C) from \ACADWIN\ADS, to ensure 
  166. that the compiler is set up properly.
  167. Tip: Read README.ADS from ACADWin. Use -NOSTUB switch 
  168. with PharLap linker 5.0 or later. Earlier versions of PharLap do not 
  169. need this switch.
  170. Place the files L2C.EXE (Lips2C translator) and DOS4GW.EXE 
  171. (Watcom DOS extender) into directory pointed by a system variable 
  172. PATH. We suggest C:\DOS or C:\ACAD directory.
  173. Place MWL2CWIN.LIB and L2C.H files into \ACADWIN\ADS 
  174. directory. Point to this directory  with L2C variable:
  175. SET L2C=C:\ACADWIN\ADS
  176. Change IPATH variable to include \ACADWIN\ADS directory:
  177. SET IPATH=C:\HIGHC\H;C:\ACADWIN\ADS
  178. Note that paths must be set before Lisp file is converted into C 
  179. source. L2C uses the values of these variables to produce .BAT and 
  180. .MW files. If those values are not set or set properly, .BAT and .MW 
  181. files may not compile the C files. This does not, however, corrupt 
  182. produced C code in any way.
  183. Copy the file ADS.ICO from \ACADWIN\ADS\WIN directory to 
  184. your working directory. Again, this only affects the compilation with 
  185. produced .BAT and other files.
  186. 2.5. DOS Example (Watcom)
  187. Place the rest of the files into your working directory. These files are 
  188. included only as a demonstration and can be deleted altogether.
  189. Example:
  190. Let us assume that you have correctly set up the Watcom C/386 9.0 
  191. to the C:\WATCOM directory. Thus, when you type SET, you might 
  192. see something like 
  193. PATH=...C:\ACAD;C:\WATCOM\BIN;C:\WATCOM\BINB
  194. ;C:\WATCOM\LIB386\DOS;... 
  195. WATCOM=C:\WATCOM\.
  196. INCLUDE=C:\WATCOM\H
  197. In order to use ADS, your C:\ACAD\ADS directory should contain at 
  198. least the following files:
  199.     WCADS90.LIB
  200.     ADSLIB.H
  201.     ADSDLG.H
  202.     ADS.H
  203.     ADSCODES.H
  204. If those files are missing, you can copy them from our distribution.
  205. Now you can copy L2C.EXE to C:\ACAD directory (listed in path), 
  206. and L2C.H, L2C.LIB into C:\ACAD\ADS directory. Also, you should 
  207. change the INCLUDE variable so that Watcom C/386 will search for 
  208. header (.h) files also in C:\ACAD\ADS directory:
  209. SET INCLUDE=C:\WATCOM\H;C:\ACAD\ADS
  210. And finally, you should set the L2C system variable to 
  211. C:\ACAD\ADS:
  212. SET L2C=C:\ACAD\ADS
  213.  
  214.  
  215. 3. THE USAGE
  216. 3.1. COMMAND LINE INPUT
  217. The syntax is:
  218.  L2C [options] file [file...]
  219. where options are
  220. d        includes debugging information
  221. oname    sets the output file name to 'name', instead to the 
  222.         name of 1st input file name
  223. c        compiler (cWAT = Watcom, cMW = Metaware)
  224. e        compiles every function separately
  225. y        "yes" to all questions (except for the registration)
  226. n        "no" to all questions (except for the registration)
  227. t        target (currently Dos or WIndows)
  228. ?        displays simple help
  229. The option must be preceded with either / or - character. If an invalid 
  230. option is specified, program terminates with a message.
  231. File is the name of AutoLISP source file. L2C produces file.C 
  232. file (if more than one file is specified, the first name is taken, unless 
  233. /oname option is used). In addition, one file is produced for each 
  234. (defun...) and (lambda...) These additional files have the name of the 
  235. main file file padded with underscores ("_") to the length of total 8 
  236. (eight) characters, and then up to the last three characters are replaced 
  237. with a number, starting from 0.
  238.  If two different applications are compiled on the 
  239. same directory, then the corresponding main file 
  240. names must differ in first five  characters, or the 
  241. files of one application will tackle with the files 
  242. from the other application. 
  243. The order of files and options is insignificant. They can also be mixed. 
  244. Example: to compile DLINE.LSP, one could use the following 
  245. command: 
  246. L2C ai_utils startup /odline dline /d
  247. which would compile AI_UTILS.LSP, STARTUP.LSP, and 
  248. DLINE.LSP into DLINE.C and DLINE__0.C, ..., DLINE_64.C, 
  249. DLINE.BAT, DLINE.MAK, and DLINE.LNK. For Windows, also 
  250. DLINE.RC and DLINE.DEF would be generated. 
  251. 3.2. INTERACTIVE INPUT
  252. Alternatively, one can invoke L2C without parameters:
  253.  L2C
  254.  Input file name (.lsp):
  255. The user then enters one file name per line. The input is terminated 
  256. with a blank line. Then the question appears:
  257. Include debugging information (<Yes>/No/?):
  258. The answer "Yes" is equivalent to specifying the /d switch. The 
  259. answer "No" is equivalent to omiting that switch.
  260. Next, the target environment and compiler are specified:
  261. Target (<Dos>/Windows/?):
  262. Compiler (<Watcom>/Metaware/?)
  263. Currently supported are DOS and Windows 3.1 operating systems. 
  264. The code produced is the same in both cases. However, the support 
  265. files (.BAT, .MAK, .LNK, and optionally .RC and .DEF) files are 
  266. different for those two environments. Those two questions 
  267. correspond to /t and /c switches.
  268. Next, the way how produced source code will be compiled, is 
  269. choosen:
  270. Arrange for separate compilation of each 
  271. file (Yes/<No>/?):
  272. This question corresponds to the /e switch. The answer "Yes" is 
  273. equivalent to specifying that switch, and the answer "No" is equivalent 
  274. to omitting it.
  275. Next, an answer to all questions can be specified:
  276. Answer to all questions (Yes/No/<Ask>/?):
  277. This question corresponds to /y and /n switches. The answer "Yes" 
  278. is equivalent to specifying the /y switch, the answer "No" is 
  279. equivalent to specifying the /n switch, and the answer "Ask" is 
  280. equivalent to omitting both two switches.
  281. Next, the code commenting can be disabled:
  282. Comment the produced code (<Yes>/No/?):
  283. This question corresponds to /b switch. The answer "Yes" is 
  284. equivalent to specifying that switch and the answer "No" is equivalent 
  285. to omiting it.
  286. Finally, user can specify the output file name:
  287. Output file name (5 chrs significant) <>:
  288. This question corresponds to an /o switch. In angle brackets, the 
  289. name of the first file appears as a default output file name. If the 
  290. default file name is longer than 5 characters, then only the first five 
  291. characters are in the upper case, and the rest are in the lower case 
  292. letters. One should be aware, that Lisp2Cads will use only the first 5 
  293. characters for all files but the main .C file, the .BAT file, and the 
  294. .LNK file.
  295. Example: to compile DLINE.LSP, one could use the following 
  296. command:
  297. L2C
  298. Input file name (.LSP): AI_UTILS
  299. Input file name (.LSP): STARTUP
  300. Input file name (.LSP): DLINE
  301. Input file name (.LSP):
  302. Include debugging information (<Yes>/No/?): 
  303. Yes
  304. Target (<Dos>/Windows/?): Dos.
  305. Compiler (<Watcom>/Metaware/?): Watcom
  306. Output file name (5 char..) <AI_UTils>: 
  307. DLINE
  308. which would compile AI_UTILS.LSP, STARTUP.LSP, and 
  309. DLINE.LSP into DLINE.C and DLINE__0.C, ..., DLINE_64.C, 
  310. DLINE.BAT, and DLINE.LNK.
  311. 3.3. PROJECT FILE
  312. The third option is to invoke the compiler with the name of the 
  313. project file, preceded with an @ character. Project file is an ASCII 
  314. file. Each line is either a comment (starts with an * (asterisk) or ; 
  315. (semicolon) in the 1st column), a file name, or an option. The syntax 
  316. for options is the same as in the command line case. A sample project 
  317. file (with no comments) might look like:
  318. ai_utils
  319. startup
  320. dline
  321. /odline
  322. /d
  323. /tWIN
  324. /cWAT
  325. /n
  326. The default extension for a project file is .L2C. You can specify a full 
  327. project file name, if necessary.
  328. Example: to compile DLINE.LSP, one could use the following 
  329. command:
  330. L2C @DLINE
  331. which would compile AI_UTILS.LSP, STARTUP.LSP, and 
  332. DLINE.LSP into DLINE.C and DLINE__0.C, ..., DLINE_64.C, 
  333. DLINE.BAT, DLINE.MAK, and DLINE.LNK.
  334. 3.4. SWITCHES
  335. /D - Debugging
  336. When this switch is used, a code is added to every function that prints 
  337. out the function name and its arguments, and simple debugger is 
  338. enabled Also, batch and link files are set to include the debugging 
  339. information. You will find more information about debugger in 
  340. Section 6.3.
  341. /Oname - Output filename
  342. You can specify the output file name. If none is specified, the first file 
  343. name is taken.
  344. /C - Compiler
  345. Currently supported are Watcom C/386 compiler (/CWAT) and 
  346. MetaWare High C/C++ compiler (/CMW). By default, compiler 
  347. assumes Watcom C/386. If you use MetaWare C/C++, then use /CMW 
  348. switch.
  349. /E - Separate compiling
  350. By default, all the functions are included to the main file during 
  351. compile time. In this way, the C compiler has only to be loaded once, 
  352. and the compilation process is significantly faster. Using /E switch, 
  353. you force the L2C to produce several source files; one main source 
  354. and one source file for every LISP function. They are compiled 
  355. separately and then linked together. This way, you can edit functions 
  356. without recompiling all the source code over and over again. Note 
  357. that this is not simply the question of the batch and link files produced 
  358. by L2C. The headers of C source files are also different.
  359. /Y - YES to all questions
  360. /N - NO to all questions
  361. Specifies that answers to all the questions are Yes or No, respectively. 
  362. If you specify both switches, the last is used.
  363. These two switches do not apply to the question 
  364. on registration.
  365. /T - target system (DOS or Windows)
  366. The target is the system under which the compiled application will be 
  367. running. Currently two target systems are supported: MS-DOS and 
  368. MS-Windows. To choose MS-DOS as a targeting environment, use 
  369. /TDOS switch. To use MS-Window as a targeting system, use 
  370. /TWIN switch. The former is default. 
  371. The code generated is the same for all the targets. The difference is in 
  372. the files that Lisp2C produces to compile the application.
  373. /B - brief code generator
  374. Normally, Lisp2C inserts corresponding parts of Lisp code as a 
  375. comment to the prodused C code. This is intended to ease the code 
  376. modification process. However, the size of produced .C files is 
  377. expanded significantly. If you don't intend to modify the code or you 
  378. don't have enough disk space, specify /b switch to surpress the 
  379. insertion if the comments.
  380. /? - Help
  381. This switch displays a simple remainder of the switches and stops the 
  382. compiler execution.
  383. 3.5. COMPILING THE CODE (WATCOM)
  384. The C source file must be translated with Watcom C/386 compiler. 
  385. The object (.OBJ) file produced by Watcom C/386 compiler must be 
  386. further linked together with WCADS90.LIB and L2C.LIB libraries 
  387. under DOS, or with WINADS.OBJ, WINADS.LIB and 
  388. WINL2C.LIB libraries under Windows.
  389. To simplify the job, Lisp2C translator, automatically produces several 
  390. files, a batch file named name.BAT, make file name.MAK, a link file 
  391. name.LNK, and possibly simple resource file name.RC and a simple 
  392. definition file name.DEF. Batch file invokes the make utility to 
  393. compile and link all files into an .EXP file under DOS, or .EXE file 
  394. under Windows. The file file.LNK uses the system variable L2C to 
  395. locate the libraries. If the user hasn't preset the variable, file.BAT 
  396. sets it to point to a \ACAD\ADS directory (on the current drive).
  397. If a single file is to be compiled, the command
  398.  wcc386p /mf /3s /fpi87 <file>
  399. can be used for a DOS target. The meanings of the options are
  400.     /mf         generate the code for the flat memory model,
  401.     /3s        pass the arguments on the stack,
  402.     /fpi87         generate in-line calls to a math coprocessor.
  403. Similar command for Windows environment would be
  404.  wcc386p /mf /3s /fpi87 /s /j /opmaxet /dWIN 
  405. /dWATWIN /zW <file>
  406. where
  407.     /mf         generate the code for the flat memory model,
  408.     /3s        pass the arguments on the stack,
  409.     /fpi87         generate in-line calls to a math coprocessor,
  410.     /s        remove stack overflow checks,
  411.     /j        change char default from unsigned to signed,
  412.     /opmaxet    controls several optimization parameters,
  413.     /dWIN        defines WIN symbol (as with #define),
  414.     /dWATWIN    defines WATWIN symbol, and
  415.     /zW        uses Microsoft Windows entry/exit code.
  416. Note that, during the compilation, a compiler might issue several 
  417. warning messages. They refer to undefined macro symbols (used in 
  418. other systems), unreachable statements, and unreferenced variables. 
  419. This is perfectly OK, as long as no error is produced.
  420. 3.6. LINKING (WATCOM)
  421. To link the compiled files together, it is best to use the generated 
  422. linker file, as all the file names must be listed. A command
  423.  wlink @file.lnk
  424. should do the trick. However, do not forget the "@" symbol or the 
  425. file extension!
  426. The resulting file.EXP file is ready to be XLOADed.
  427. 3.7. BINDING (WATCOM)
  428. When compiling for Windows environment, the linker produces .REX 
  429. file. This file has to be further binded with resource and definition 
  430. files, file..RC and file.DEF, respectively. This can be achieved 
  431. with the command
  432. wbind file -R file.rc file.exe
  433. Make sure that the ADS.ICO file is placed in the current directory, 
  434. You can find that file in \acadwin\ads directory.
  435. Example.
  436. To compile DEMO.LSP the command
  437. L2C DEMO
  438. produces the following C source and some support files:
  439. DEMO.C    contains the main loop
  440. DEMO__0.C    code for (defun qsort ...)
  441. DEMO__1.C    code for (defun c:stat ...)
  442. DEMO__2.C    code for (defun c:gc ...)
  443. DEMO__3.C    code for (defun c:interpreter ...)
  444. DEMO__4.C    code for (defun S::STARTUP ...)
  445. DEMO.BAT    batch files that starts make utility,
  446. DEMO.MAK    make file,
  447. DEMO.LNK    link file used by DEMO.MAK.
  448. DEMO.RC    is produced under Windows only, a resource file.
  449. DEMO.DEF    is produces under Windows only, a definition file.
  450. Then the command
  451. DEMO
  452. produces (among others) ADS module, DEMO.EXP file , which can 
  453. be later loaded into AutoCAD with the command
  454. (xload "demo").
  455. Under Windows, DEMO.EXE is produced, which can be XLOADed 
  456. into AUTOCAD for WIndows.
  457.  
  458.  
  459. 4. SUPPORTED FUNCTIONS
  460. Lisp2Cads *DEMO* supports AutoLISP R12 functions, except AME 
  461. and ASE support. Here is the brief list of supported functions:
  462. (* *error* + - / /= 1+ 1- < <= = > >= abs alloc and append apply ascii 
  463. assoc atan atof atoi atom atoms-family(*) boole boundp caaaar caaadr 
  464. caaar caadar caaddr caadr caar cadaar cadadr cadar caddar cadddr 
  465. caddr cadr car cdaaar cdaadr cdaar cdadar cdaddr cdadr cdar cddaar 
  466. cddadr cddar cdddar cddddr cdddr cddr cdr chr cond cons cos defun 
  467. eq equal eval exit exp expand expt fix float foreach gc gcd getenv if 
  468. itoa lambda last length list listp load log logand logior lsh mapcar max 
  469. mem member min minusp not nth null numberp open or prin1 princ 
  470. print progn quit quote read read-char read-line rem repeat reverse set 
  471. setq sin sqrt strcase strcat strlen subst substr terpri trace type untrace 
  472. ver vmon while write-char write-line zerop ~ acad_colordlg 
  473. acad_helpdlg acad_strsort ads alert angle angtof angtos command 
  474. cvunit distance distof entdel entget entlast entmake entmod entnext 
  475. entsel entupd findfile getangle getcorner getdist getfiled getint 
  476. getkword getorient getpoint getreal getstring getvar graphscr grclear 
  477. grdraw grread grtext grvecs handent initget inters menucmd nentsel 
  478. nentselp osnap polar prompt redraw regapp rtos setvar ssadd ssdel 
  479. ssget sslength ssmemb ssname tablet tblnext tblsearch textbox textscr 
  480. trans vports wcmatch xdroom xdsize xload xunload load_dialog 
  481. unload_dialog new_dialog new_dialog start_dialog done_dialog 
  482. term_dialog action_tile mode_tile get_attr get_tile set_tile start_list 
  483. add_list end_list dimx_tile dimy_tile start_image vector_image 
  484. fill_image slide_image end_image client_data_tile)
  485.  
  486.  
  487. 5. DIFFERENCES AND LIMITATIONS
  488. 5.1. EXPRESSIONS OUTSIDE THE FUNCTIONS
  489. Only Lisp expressions inside Lisp functions are compiled. Other 
  490. expressions are merely skipped (and a warning message is generated). 
  491. They can be collected automatically into S::L2CSTARTUP function 
  492. (into the file ?????__S.LSP).
  493. 5.2 NUMBER OF ARGUMENTS
  494. User functions in Lisp2Cads can only have up to 32 arguments if they 
  495. are ever to be evaluated using EVAL, APPLY or MAPCAR function.
  496. 5.3. PASSING SYMBOLS, SUBROUTINES ETC.
  497. Currently, there is no (regular) way to exchange SYMbols, 
  498. SUBRoutines, EXSUBRoutines and some other exotic data types 
  499. between an ADS application and an AutoLISP environment. 
  500. Functions that expect symbols as their arguments (as when calling 
  501. parameters by reference) should be rewritten in a way that they would 
  502. accept strings as arguments and then READ out the symbol. This only 
  503. applies to a function that is called from AutoLISP. Function called 
  504. directly from another L2C function can pass symbols without any 
  505. limitations.
  506. 5.4. PASSING LISTS OF INTEGERS ETC.
  507. The transfer of the objects between AutoLISP and an ADS 
  508. application is not an exact one. For example, if the function FOO is 
  509. invoked with a list of two integers as the only argument: Command: 
  510. (FOO '(1 2)), then an ADS application will receive this as a 2D 
  511. point, with integers already converted into reals. As most of the 
  512. functions that expect real value they work well if given an integer 
  513. argument, while the opposite might not be true, Lisp2Cads application 
  514. will transform any whole element of 2D or 3D point passed from 
  515. AutoLISP to integer. Therefore an unexpected results may occur 
  516. every now and then.
  517. Example:
  518. AutoLisp value is seen by Lisp2C as
  519. AutoLISP
  520. Lisp2C
  521.  
  522. (1 2 3)
  523. (1 2 3)
  524.  
  525. (1.0 2.0 3.0)
  526. (1 2 3)
  527.  
  528. (1.1 2.2 3.3)
  529. (1.1 2.2. 3.3)
  530.  
  531. (1 2.2 3.3)
  532. (1 2.2 3.3)
  533.  
  534. (1 2.0 3.3)
  535. (1 2 3.3)
  536.  
  537. 5.5. BUILD-IN PRIMITIVES
  538. Build-in primitives are considered as a keywords in L2C. You should 
  539. not use them as an ordinary symbols, or the results will be 
  540. unpredictable. The only exception is the TYPE function, that returns 
  541. 'SUBR type on *every* build-in primitive, except on 
  542. ACAD_COLOR.
  543. Unfortunately, you cannot check whether an 
  544. external function has to be loaded  by matching 
  545. its type against EXSUBR type symbol.
  546. 5.6. GLOBAL SYMBOLS
  547. When a global symbol is set, also its value in AutoLISP is updated, 
  548. unless a value contains a non-re presentable datum (such as a symbol 
  549. or a function). However, once a Lisp2C cannot pass a symbol value to 
  550. an AutoLISP, it doesn't check that symbol's value in AutoLISP until a 
  551. Lisp2C application assigns this symbol to a value such that it can be 
  552. passed to an AutoLISP. (This is necessary as otherwise global 
  553. symbols would either be number, strings or lists of numbers or strings, 
  554. or they would evaluate to NIL.) This also gives rise to a simple trick 
  555. that prevents Lisp2C from constantly updating value of a global 
  556. symbol in AutoLISP. Assume, for example, that a global variable X 
  557. must hold an integer value and that we don't want to pass this value to 
  558. AutoLISP every time X is referenced (this passing mechanism can 
  559. also be time-consuming). Therefore one would set X to a (dotted) 
  560. pair (X . <number>) instead simply to a number. In this way Lisp2C 
  561. will quickly determine it cannot pass a symbol's value to AutoLISP (as 
  562. already it cannot pass the very first element of a list) and will in turn 
  563. refuse to pass to or import from AutoLISP the value of X as long as 
  564. X is stored in this format. And, as usually, the value of X can be 
  565. obtained using CADR function.
  566. Anyway, it is generally much better practise to avoid using global 
  567. variables as much as possible.
  568. 5.7. A SYMBOL TABLE
  569. A symbol table is used to store names (and values) of the symbols. 
  570. Currently, symbol table has 631 entries. The hashing algorithm 
  571. guarantees that at least half of the table will be used before Lisp2C 
  572. will complain.
  573. 5.8. NENTSEL, NENTSELP
  574. Functions NENTSEL and NENTSELP will return a three-element list 
  575. when the argument is a simple entity, with the third element being an 
  576. identity matrix.
  577. 5.9. ATOMS-FAMILY
  578. It was virtually impossible to reproduce the bug in AutoLISP's 
  579. (atoms-family ...) function. Therefore (atoms-family ...) returns only 
  580. the list of the symbols (as a list of symbols or as a list of strings) 
  581. without "nil's being inserted here and there. Sorry.
  582. 5.10. COMMAND
  583. In AutoLISP, (command) evaluates its arguments on-fly. To maintain 
  584. compatibility, Lisp2C compiles the command
  585. (command arg1 arg2 ... argn)
  586. into
  587. (command arg1)
  588. (command arg2)
  589. ...
  590. (command argn)
  591. 5.12. SPEED
  592. Normally, the program runs faster when compiled with Lisp2C. But 
  593. the global variables slow down the execution speed significantly. 
  594. Avoid the usage of global variables wherever possible. Not to mention 
  595. that global variables as a rule reflect a poor programming style.
  596.  
  597.  
  598. 6. FEATURES
  599. 6.1. A GARBAGE COLLECTOR
  600. The garbage collector not only reclaims a node space, but also 
  601. releases unused selection sets and closes all unused files. When 
  602. unloading the application, garbage collection is invoked automatically. 
  603. 6.2. S::L2CSTARTUP FUNCTION
  604. This function, if present, is invoked automatically during XLOAD. It 
  605. can already use all functions compiled with Lisp2Cads.
  606. 6.3. AUTOMATIC S::L2CSTARTUP GENERATION
  607. When the first statement that is not a function is read, you can select 
  608. whether this and all subsequent statements should be collected into 
  609. S::L2CSTARTUP function. You have to be careful, though, not to 
  610. include (load ...) statements. It is generally better idea to compile the 
  611. file than to (load) it. You are prompted for each statement whether to 
  612. include it into S::L2CSTARTUP or not (as long as /N or /Y switches 
  613. are not used). You can check the ?????__S.LSP function and edit it to 
  614. meet your needs. Then you should rename it and recompile the 
  615. program, adding this function to the file list (e.g. in project file), and, 
  616. during second iteration, you should not generate this file again.
  617. Note: if you already have S::L2CSTARTUP on 
  618. the disk and L2C generates its own one, the 
  619. latter will be executed (for it is compiled later).
  620. 6.4. SCOPING
  621. Lisp2Cads supports entirely the scoping mechanism from AutoLISP 
  622. interpreter.
  623. 6.5. MEM FUNCTION
  624. Function (MEM) now accepts a single optional argument. If present 
  625. and not nil, MEM scans the symbol table and prints out the values 
  626. of all the symbols. Note that symbol can have more then a single 
  627. value, one in each instance of a function.
  628. 6.6. DEBUGGER
  629. The /d switch enables a L2C debugger. This has the following 
  630. features:
  631. *    the program execution can be monitored step by step,
  632. *    intermediate results are printed out (optionally),
  633. *    at the break point, any Lisp expression can be entered, so the 
  634. symbols can be viewed and even set.
  635. When the break point is reached, the following message appears:
  636. Function <name>, depth <n>. Command <cmd>.
  637. Here, <name> is the Lisp name of the function that is being executed. 
  638. <n> is a depth, or level of  the command that will be executed first. 
  639. In the following example, the depth of every function is indicated with 
  640. the corresponding number:
  641. (defun depth () 
  642.   (setq1 a (1+2 (*3 (sin4 x) (cos4 (read5 
  643. y)))))
  644. )
  645. The <cmd> is the command that will be executed next ("User 
  646. function", if user function will be called). Then, the following 
  647. commands are available:
  648. Over/Return/Go/Verbose/lisp expr <1>:
  649. *    Over will step the execution at the first command having the same 
  650. or smaller depth as the current command, in the scope of the 
  651. current function. If a user function is called, another command in 
  652. that function may have the same depth, but the execution will not 
  653. be broken. If no other command inside this function has this or 
  654. smaller depth, the execution will break at the end of the function.
  655. *    Go will break the execution of the program only when returning to 
  656. an AutoLisp 
  657. *    Return will break the execution of the program only at the end of 
  658. the function.
  659. *    environment. However, the next time some L2C-compiled function 
  660. is invoked, the debugger is here again.
  661. *    Verbose turns on the printing  of the commands results.
  662. *    Silent turns off the printing of the commands results.
  663. *    lisp expr is any Lisp expression. This string is processed by 
  664. (read...) and (eval..) pair.
  665. *    <1> is the number of steps  that are to be executed before the 
  666. program execution is broken again. One (1) means single step, and 
  667. greater numbers skip several steps. This has to be a non-negative 
  668. integer.
  669. To effectively use a debugger, one has to have a printed LISP 
  670. program (or function) being debugged. There is no line information 
  671. (currently).
  672. 7. A PROGRAMMER'S VIEW
  673. 7.1. SymExp
  674. The SymExp .is a basic type in Lisp2C. It is similar in part to a resbuf 
  675. structure in ADS, but more powerful. In short, it is designed to 
  676. represent any Lisp data structure. The structure of SymExp can be 
  677. found in L2C.H file. However, to preserve compatibility with the 
  678. subsequent releases, you should not access  parts of the structure 
  679. directly, but rather through several procedures, provided for this 
  680. purpose. These procedures include:
  681. SymExp MakeNumber (long);
  682. SymExp MakeReal (ads_real);
  683. SymExp MakeString (char *);
  684. SymExp MakeSymbol (char *);
  685. SymExp MakeFunction (SymExp (*f)());
  686. SymExp MakeFile (FILE *);
  687. SymExp MakeEName (ads_name);
  688. SymExp MakePickSet (ads_name);
  689. SymExp MakePoint (ads_point);
  690. SymExp MakeMatrix (ads_matrix);
  691. 7.2. A FUNCTION CALL MECHANISM
  692. A call to a user written function
  693. (myfunc arg1 arg2 ... argn)
  694. is translated as follows.
  695. 1.    The symbol myfunc is fetched from the symbol list table.
  696. 2.    If the symbol is a function, then the function is called.
  697. 3.    If the symbol is a list, it is evaluated.
  698. 4.    In any other case, myfunc is invoked (via ads_invoke).
  699. There are n+1 arguments passed to a  function. The last argument is 
  700. always a EndArgList symbol. This convention is used to allow the 
  701. functions having variable number of arguments. In AutoLisp one 
  702. cannot write such a function. However, in C, this is no problem. Via 
  703. va_start, va_arg, and va_end macros, one fetches one SymExp after 
  704. anoter, until there is a EndArgList argument.
  705.  
  706. Example: the following function will act as a (print ...), but accepting 
  707. as many arguments as supplied.
  708.  
  709. SymExp myfunc (SymExp S,...)
  710. {
  711.     va_list  args;
  712.     SymExp   arg;
  713.  
  714.     if (S == EndArgList)        // no arguments
  715.         return (NULL);
  716.     LSP_Print (S, EndArgList);  // 1st argument
  717.     va_start (args, S);
  718.     while ((arg = va_arg (args, SymExp)) != 
  719. EndArgList)
  720.         LSP_Print (S, EndArgList);
  721.     va_end (args);
  722. } // myfunc
  723.  
  724. Note that you have to modify either L2C.H file (highly 
  725. unrecommended), or an aplicattion┤s header file, and accordingly 
  726. either modify one of the source files, or the make file, to compile this 
  727. function and link it to the application. Further releases of Lisp2C will 
  728. include additional mechanisms to assist you in creating your own 
  729. libraries.
  730. 7.3. NAMING CONVENTIONS
  731. Wherever possible,  LISP symbol names are kept in C source files. To 
  732. avoid name collision, they are being capitalised (first letter in 
  733. uppercase and the rest in lowercase letters). In addition, all build-in 
  734. functions have a prefix LSP_ or ADS_, and might have more letters in 
  735. uppercase. Special characters (everything other than a letter, digit, or 
  736. underscore) cannot be handled by C. This characters are replaced with 
  737. a three-letter code (e.g., a colon (:) is replaced with COL). This 
  738. guarantees that two different names in LISP will translate into two 
  739. different names in C, and additionally, no LISP name can match the 
  740. name of functions in Lisp2C library, as all functions in this library have 
  741. more than one capital letter, and none contains any three-letter 
  742. sequence mentioned above.
  743.  
  744.  
  745. APPENDIX
  746. A. EXAMPLE: DLINE.LSP
  747. As an example, we shall examine closer the translation of DLINE.LSP 
  748. file (located in your AutoCAD SUPPORT directory) for 
  749. AUTOCAD/386. The following steps should be followed:
  750. A number of files will be produced during the compilation, so it is best 
  751. to do all the compilation in a separate directory. Make sure you can 
  752. run L2C.EXE program (either place a copy of it in the working 
  753. directory, or place it into a directory listed in PATH). Make sure that 
  754. Watcom compiler will be able to locate L2C.H header file (Watcom 
  755. compiler can locate any header file in current directory or in the 
  756. directory pointed to by a system INCLUDE variable) and make sure 
  757. that L2C system variable is pointing to a directory containing both 
  758. WCADS90 and L2C library files. In general, read section 2 again.
  759. Once you have a working directory, copy the file DLINE.LSP from 
  760. \ACAD\SUPPORT directory (you might have a different name, and 
  761. perhaps a drive letter is necessary as well). As stated in section 5.1., 
  762. lisp expressions that are not inside a function are ignored. As those 
  763. expressions are usually evaluated during load time, it is important to 
  764. understand what they are doing. In our case, the expression at the line 
  765. 204 loads the file containing the support functions. Therefore, we 
  766. must copy the file AI_UTILS.LSP form \ACAD\SUPPORT directory 
  767. as well. Look further. At the lines 2121-2124 four global variables are 
  768. set that enables DLINE command to retain several parameters 
  769. between two successive calls. The obvious solution would be to copy 
  770. those four expressions into another file, say DL.LSP, and load that file 
  771. *before* calling DLINE command. Unfortunately this won't work. 
  772. The reason is that both dl:snp and dl:brk are set to T, and T is a 
  773. symbol. According to 5.5 and 5.7., one cannot pass a symbol from 
  774. AutoLisp to Lisp2Cads. The correct solution is to copy these 
  775. expressions into a file, say STARTUP.LSP, and enclose them into a 
  776. function S::L2CSTARTUP . In this way those variables will be set 
  777. during xload.
  778. Your STARTUP.LSP file should now look something like this:
  779. (defun S::L2CSTARTUP ()
  780.  (if (null dl:ecp) (setq dl:ecp 4))  
  781. ; default to auto endcaps
  782.  (if (null dl:snp) (setq dl:snp T))  
  783. ; default to snapping ON
  784.  (if (null dl:brk) (setq dl:brk T))  
  785. ; default to breaking ON
  786.  (if (null dl:osd) (setq dl:osd 0))  
  787. ; default to center align
  788. )
  789. and in your working directory you should have the following files:
  790. DLINE.LSP
  791. AI_UTILS.LSP
  792. STARTUP.LSP
  793. We could now compile those files with a single command:
  794. L2C DLINE AI_UTILS STARTUP
  795. The order of the parameters is not important. However, we would 
  796. place DLINE.LSP file the first, to get DLINE??? file names
  797. But there is an easier way. Using a project file (supplied with a 
  798. distribution), one only has to say:
  799. L2C @L2C
  800. During the compilation, L2C encounters the statements that are not 
  801. inside any functions. After the first statement, (LOAD ...) function is 
  802. read, L2C asks
  803.     Create DLINE__S.LSP with 
  804. S::L2CSTARTUP? (<Yes>/No)
  805. As we already have our own S::L2CSTARTUP function, we answer 
  806. "No". L2C produces files:
  807. DLINE.C                    main loop
  808. DLINE__0.C                 1st function
  809. DLINE__65.C                last function
  810. DLINE.BAT                  this one compiles 
  811. everything
  812. DLINE.LNK
  813. We can now compile and link the application using the command
  814. DLINE
  815. Watcom C/386 9.0 complains every time for a symbols that are not 
  816. defined. This is perfectly all right as long as there are 5 warnings per 
  817. file. Anything more is suspicious and should be reported immediately.
  818. If everything went OK (and it should), you are ready to xload the 
  819. application. Start AutoCAD and at the Command: prompt type:
  820. (xload "dline")
  821. Ljubljana, 22th June 1993
  822.  STARTUP.LSP is also supplied with Lisp2Cads, in case you don't fill like typing.
  823.  
  824.  
  825. Lisp2C 1.9    25.06.93    (C) BASIC d.o.o.
  826.  
  827. 2
  828.  
  829.  
  830.